package com.wzj.uarmor.controller;


import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.wzj.uarmor.entiy.Remote;
import com.wzj.uarmor.utils.ConnectLinuxUtil;
import com.wzj.uarmor.utils.ResponseVO;
import com.wzj.uarmor.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * ssh2演示
 *
 * @author whong
 * @date 2023/03/18
 */
@RestController
@RequestMapping(value = "/ssh")

public class SSH2Demo {

    @Autowired
    private  Remote remote;

   @GetMapping("/yc")
   public ResponseVO  YCssh (@RequestParam String cmd) throws JSchException {
       //        获取连接
       Session session =  ConnectLinuxUtil.getSession(remote);
       List list =  ConnectLinuxUtil.remoteExecute(session,cmd);
       System.out.println("命令返回 >> " + list);
       System.out.println("长度 >> " + list.size());

       return ResultUtil.success("成功",list);
   }

    @GetMapping("/bd")
    public ResponseVO  BDssh (@RequestParam String cmd) throws JSchException, IOException {
        //        获取连接
        List list =  ConnectLinuxUtil.ProcessExecute(cmd);
        System.out.println("长度 >> " + list.size());
        return ResultUtil.success("成功",list);
    }

}
